import util.PATH as PATH
import os

def get_bugs_label():
	# 0: bug_id , 1: 代表assign_to的字符串, 7: 代表component字段
	# 这里使用7号字段来重现实验, 借此检验代码正确与否
	labels = {}     # key:id, value: assign_to
	with open(PATH.path_bug_msg_all, 'r') as reader:
		for line in reader.readlines():
			words = line.strip().split('\t')
			labels[words[0]] = words[1:]
	return labels

def get_docs_list():
	path_doc = '/home/wanglinhui/Desktop/二师兄/small_docs/'  # 小数据集, 测试用
	names = os.listdir(path_doc)
	return names

def write_to_file(datas, filepath):
	with open(filepath, 'w') as writer:
		for i in range(len(datas)):
			for j in range(len(datas[i])):
				writer.write(datas[i][j] + '\t')
			writer.write('\n')

if __name__ == '__main__':
	labels = get_bugs_label()
	docs_list = get_docs_list()
	small_bug_msg_all = []
	for name in docs_list:
		small_bug_msg_all.append([name] + labels[name])
	write_to_file(small_bug_msg_all, PATH.path_small_bug_msg_all)